using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace Acms.SqlDal
{
    public class PostMenuDal : Base
    {
        public PostMenuDal() : base() { }

        public enum Fields
        {
            PostId,
            MenuId,
            Included
        }

        protected override void ReadRecord(Hashtable table, SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.PostId, reader, table);
            GetReaderValue<int>(Fields.MenuId, reader, table);
            GetReaderValue<bool>(Fields.Included, reader, table);
        }

        public Hashtable[] GetAllByPostId(int postId)
        {
            SqlCommand cmd = CreateCommand("GetAllByPostId");
            AddInputParameter(cmd, "PostId", postId, SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }

        public void Update(int postId, int menuId, bool included, ref object concurencyId)
        {
            SqlCommand cmd = CreateCommand("Put");
            AddInputParameter(cmd, "PostId", postId, SqlDbType.Int);
            AddInputParameter(cmd, "MenuId", menuId, SqlDbType.Int);
            AddInputParameter(cmd, "Included", included, SqlDbType.Bit);
            AddInputParameter(cmd, "VersionId", concurencyId, SqlDbType.Timestamp);
            ExecuteCommand(cmd);
            concurencyId = GetOutputValue<byte[]>(cmd, "VersionIdOut");
        }
    }
}
